package com.example.quanlithuchi;


import Presenter.LoaiThuChiPresenter;
import View.ILoaiThuChiDetailView;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoaithuchiDetailActivity extends Activity implements ILoaiThuChiDetailView {

	Button btnAdd,btnCancelButton;
	EditText txtTenLoaiThuchi,txtGhichuThuchi;
	int isthuchi=0;
	LoaiThuChiPresenter thuChiDetailPresenter;
	Context context=this;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_loaithuchi_detail);
		btnAdd=(Button) findViewById(R.id.btnSaveLoaithuchi);
		btnCancelButton=(Button) findViewById(R.id.btncancelLoaithuchi);
		btnAdd.setOnClickListener(onClickListener);
		btnCancelButton.setOnClickListener(onClickListener);
		txtTenLoaiThuchi=(EditText) findViewById(R.id.txttenloaithuchi);
		txtGhichuThuchi=(EditText) findViewById(R.id.txtghichu_loaithuchi);
		thuChiDetailPresenter=new LoaiThuChiPresenter(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_loaithuchi_detail, menu);
		return true;
	}
	OnClickListener onClickListener=new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.btnSaveLoaithuchi:
			{
				long result=thuChiDetailPresenter.insert();
				if (result>=0) {
					
					Log.d("insert", "thanh ong");
					Intent intent=new Intent();
					intent.putExtra("tenloai", getTenLoai());
					intent.putExtra("ghichu", getGhichu());
					intent.putExtra("id", result);
					intent.putExtra("isthuchi", isthuchi);
					setResult(1, intent);
					finish();
				}
				//Intent intent=new Intent();
				
			}
				break;
			case R.id.btncancelLoaithuchi:
			{
				setResult(2);
				finish();
				
			}
				break;

			}
		}
	};
	@Override
	public String getTenLoai() {
		// TODO Auto-generated method stub
		return txtTenLoaiThuchi.getText().toString();
	}

	@Override
	public String getGhichu() {
		// TODO Auto-generated method stub
		return txtGhichuThuchi.getText().toString();
	}

	@Override
	public int getIsthuchi() {
		// TODO Auto-generated method stub
		Intent intent=getIntent();
		isthuchi=intent.getIntExtra("isthuchi", 0);
		return isthuchi;
	}

	@Override
	public Context getContext() {
		// TODO Auto-generated method stub
		return context;
	}

	@Override
	public void setMessage(String mess) {
		// TODO Auto-generated method stub
		Toast.makeText(context, mess, Toast.LENGTH_LONG).show();
	}

	@Override
	public long getId() {
		// TODO Auto-generated method stub
		return 0;
	}

}
